<?php
//error_reporting(0);
include("imageThumb.class.php");
include("upload.class.php");
include("function.php");
$upload=new uploadFile();

//echo "<script language=\"javascript\">alert('$city_lng,$city_lat');</script>";

$upload->files= $_FILES['up_image'];
$upload->max_size='2000000';
$upload->uploaded="cache/".$_SESSION['login_mail'];
$upload->allow_types="jpeg|jpg|png|JPEG|JPG|PNG|gif|GIF";
$upload->save_path="cache/";
$upload->file_name=$_SESSION['login_mail'];
$upload->upload_file($_FILES['up_image']);

if($upload->errmsg != ""){
	$err=$upload->errmsg;
	echo "<script language=\"javascript\">alert('$err');</script>";
	//echo "<script language=\"javascript\">history.go(-1);</script>";
}else{

	$pictureup=$upload->uploaded;
	//echo "<script language=\"javascript\">alert('$upload->ext');</script>";
	
	$time = time();
	$name = $_SESSION['login_mail'].$time.".".$upload->ext;
	$maxpicture="up_image/big/".$name;
	$actual_name = iconv("UTF-8","gb2312",$maxpicture);//进行编码转换
	$minpicture="up_image/small/".$name;
	$actual_name = iconv("UTF-8","gb2312",$minpicture);//进行编码转换
	$mediapicture="up_image/media/".$name;
	$actual_name = iconv("UTF-8","gb2312",$mediapicture);//进行编码转换
	
	if($upload->ext != "gif" && $upload->ext != "GIF"){
		$resizeimage = new myThumbClass($pictureup,600,1,$maxpicture,-1,0);
		//$resizeimage = new myThumbClass($pictureup,80,1,$minpicture,-1,0);
		$resizeimage = new myThumbClass($pictureup,300,1,$mediapicture,-1,0);
		cutphoto($pictureup,$minpicture,80,80);
		//$picture=$minpicture;
		
		imageStorage($name);
	}else{
		copy($pictureup,$maxpicture);
		copy($pictureup,$mediapicture);
		//$resizeimage = new myThumbClass($pictureup,80,1,$minpicture,-1,0);
		cutphoto($pictureup,$minpicture,80,80);
		imageStorage($name);
	}

	copy($pictureup,"up_image/original/".$name);
	unlink($pictureup);

	
	
	?>
	<script type='text/javascript' src='js/jquery-1.6.min.js'></script>
	<script type='text/javascript'>
		$(window.parent.document).find("#upload_success").fadeTo(300,1);
		$(window.parent.document).find("#upload_success").css({left:$(window.parent).width()/2-40,top:$(window.parent).height()/2-20});
		setTimeout(function(){
			$(window.parent.document).find("#upload_success").fadeTo(300,0);
			$(window.parent.document).find("form input[type='file']").val("");
			$(window.parent.document).find("form input[name='img_name']").val("");
			$(window.parent.document).find("form textarea").val("");
		},1000);
	</script>
	
<?php
	//echo "<img src='image.php?user_mail=$_SESSION[login_mail]' />"
}


//图片入库
function imageStorage($path){
	$city_lng=checkSql($_POST['city_lng']);
	$city_lat=checkSql($_POST['city_lat']);
	$address=checkSql($_POST['address']);
	$name=checkSql($_POST['img_name']);
	$remark=checkSql($_POST['remark']);
	$gallery=checkSql($_POST['gallery']);
  $user=$_SESSION['login_mail'];
  $time=date("Y-m-d H:i:s",time());
	mysql_query("INSERT INTO image (name,img_path,post_time,create_time,post_user,longitude,latitude,remark,address,gallery) VALUES ('$name','$path','$time','$time','$user','$city_lng','$city_lat','$remark','$address','$gallery')") or die(mysql_error());
}
?>